Skip to content

feat(dart): support dart web platform#3608

Merged
chaokunyang merged 14 commits intoapache:mainfrom
chaokunyang:support_dart_web
Apr 23, 2026
Merged

feat(dart): support dart web platform#3608
chaokunyang merged 14 commits intoapache:mainfrom
chaokunyang:support_dart_web

Conversation

@chaokunyang
Copy link
Copy Markdown
Collaborator

@chaokunyang chaokunyang commented Apr 23, 2026

Why?

Dart web builds use JavaScript number semantics, so raw Dart int cannot safely represent the full 64-bit value space used by Fory xlang integer encodings. The Dart runtime needs browser-compatible buffer, generated serializer, and 64-bit wrapper implementations that preserve wire compatibility instead of silently corrupting JS-unsafe values.

What does this PR do?

  • Adds Dart web support through conditional native/web implementations for Buffer, generated cursors, and Int64 / Uint64 value and list wrappers.
  • Updates code generation and serializers to handle full-range signed and unsigned 64-bit fields on web, while keeping Dart int fast paths for JS-safe values.
  • Adds explicit range checks so web builds reject JS-unsafe Dart int conversions instead of writing or reading imprecise bytes.
  • Extends Dart serializer, buffer, generated-field, numeric-wrapper, typed-array, and time tests for 64-bit edge cases and browser behavior.
  • Adds Chrome test coverage to CI with dart test -p chrome for the Dart package.
  • Documents Dart web support, 64-bit integer rules, custom serializer guidance, and troubleshooting steps.

Related issues

Closes #3600

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

Yes. Dart users can now use generated serializers and manual serializers on web/browser targets. Full-range 64-bit values should use Int64 or Uint64; Dart int fields remain limited to JS-safe values on web.

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

throughput
Datatype Operation Fory TPS Protobuf TPS Fastest
Struct Serialize 5,041,693 2,073,839 fory (2.43x)
Struct Deserialize 6,395,290 4,991,881 fory (1.28x)
Sample Serialize 1,783,688 552,140 fory (3.23x)
Sample Deserialize 2,124,197 934,794 fory (2.27x)
MediaContent Serialize 952,498 438,419 fory (2.17x)
MediaContent Deserialize 1,649,039 737,340 fory (2.24x)
StructList Serialize 1,945,119 399,007 fory (4.87x)
StructList Deserialize 2,119,403 764,832 fory (2.77x)
SampleList Serialize 475,413 52,512 fory (9.05x)
SampleList Deserialize 508,939 116,236 fory (4.38x)
MediaContentList Serialize 224,925 84,860 fory (2.65x)
MediaContentList Deserialize 387,070 154,392 fory (2.51x)

@chaokunyang chaokunyang changed the title feat(dart): support dart web feat(dart): support dart web platform Apr 23, 2026
@chaokunyang chaokunyang merged commit 1d2bea8 into apache:main Apr 23, 2026
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants